<!DOCTYPE html>
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>医疗管家</title>
    <meta name="description" content="医疗管家">
    <meta name="keywords" content="医疗管家">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <style>
        .el-table__header-wrapper{ background-color: #f5f7fa;}
        .cell-bg{ background-color: #f5f7fa;}
        .cell-bg strong{ padding-left: 10px}
        .cell2{ padding: 0 10px; display: inline-block}
        .cell2:hover{ cursor:pointer; color: red; background-color: #f5f7fa;}
        .active{ cursor:pointer; color: red; background-color: #f5f7fa;}
        .search .el-table_1_column_2{ padding-left: 10px;}
    </style>
</head>

<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>会员管理<small>会员档案管理</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>会员管理</el-breadcrumb-item>
            <el-breadcrumb-item>会员档案管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <!--      搜索栏      -->
            <div class="filter-container">
                <el-input placeholder="姓名/手机号码" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item"></el-input>
                <el-button @click="findPage()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                <a class="el-button butT el-button--primary" :href=`http://localhost:9003/member/downLoadExcel?currentPage=${this.pagination.currentPage}&pageSize=${this.pagination.pageSize}&queryString=${this.pagination.queryString}`>下载当页数据</a>
            </div>

            <div class="el-table el-table--fit el-table--enable-row-transition" style="width: 100%;">

                <div class="el-table__body-wrapper is-scrolling-none">
                    <table cellspacing="0" cellpadding="0" border="0" class="el-table__body search" width="100%">
                        <colgroup>
                            <col width="80">
                            <col>
                        </colgroup>
                        <tbody>
                        <tr class="el-table__row el-table__footer-wrapper">
                            <td rowspan="1" colspan="1" class="el-table_1_column_1  cell-bg">
                                <strong>性别:</strong>
                            </td>
                            <td rowspan="1" colspan="1" class="el-table_1_column_2  ">
                                <div class="cell2" v-for="sex in sexList" :class="sex==pagination.sex?'active':''" @click="setSex(sex)">{{sex}}</div>
                            </td>
                        </tr>
                        <tr class="el-table__row">
                            <td rowspan="1" colspan="1" class="el-table_1_column_1  cell-bg">
                                <strong>年龄:</strong>
                            </td>
                            <td rowspan="1" colspan="1" class="el-table_1_column_2  ">
                                <div class="cell2" v-for="age in ageList" :class="age==pagination.age?'active':''" @click="setAge(age)">{{age}}</div>
                            </td>
                        </tr>
                        <tr class="el-table__row">
                            <td rowspan="1" colspan="1" class="el-table_1_column_1  cell-bg">
                                <strong>注册时间:</strong>
                            </td>
                            <td rowspan="1" colspan="1" class="el-table_1_column_2  ">
                                <div class="cell2" v-for="reg in regList" :class="reg==pagination.reg?'active':''" @click="setReg(reg)">{{reg}}</div>
                            </td>

                        </tr>
                        </tbody>
                    </table><!----><!----></div><!----><!----><!----><!---->
                <div class="el-table__column-resize-proxy" style="display: none;"></div>
            </div>
            <br/>
            <!--      会员信息列表      -->
            <el-table :header-cell-style="{background:'#eef1f6',color:'#606266'}" size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="name" label="用户姓名" align="center"></el-table-column>
                <el-table-column width="50" label="性别" align="center">
                    <template slot-scope="scope">
                        <!--  scope.row表示当前行的对象  -->
                        <span>{{scope.row.sex == '男' ? '男' : '女'}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="birthday" label="出生日期" align="center"></el-table-column>
                <el-table-column prop="idcard" label="身份证号" align="center"></el-table-column>
                <el-table-column prop="phonenumber" label="手机号码" align="center"></el-table-column>
                <el-table-column prop="regtime" label="注册时间" align="center"></el-table-column>
                <el-table-column width="250" prop="email" label="邮箱地址" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!--      切换页面       -->
            <div class="pagination-container">
                <el-pagination class="pagiantion" @current-change="handleCurrentChange"
                               :current-page="pagination.currentPage" :page-size="pagination.pageSize"
                               layout="total, prev, pager, next, jumper" :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增会员档案" :visible.sync="dialogFormVisible">
                    <!-- 被校验的表单必须有这个属性 ref -->
                    <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right"
                             label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="用户姓名" prop="name">
                                    <el-input v-model="formData.name"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="性别">
                                    <el-select v-model="formData.sex">
                                        <el-option label="男" value="1"></el-option>
                                        <el-option label="女" value="2"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="身份证号" prop="idcard">
                                    <el-input v-model="formData.idcard"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="手机号码" prop="phonenumber">
                                    <el-input v-model="formData.phonenumber"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="出生日期">
                                    <!--       在el-for中添加时间模块       -->
                                    <el-date-picker type="date" placeholder="选择日期" v-model="formData.birthday"
                                                    style="width: 100%;"></el-date-picker>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="注册时间">
                                    <!--       在el-for中添加时间模块       -->
                                    <el-date-picker type="date" placeholder="选择日期" v-model="formData.regtime"
                                                    style="width: 100%;"></el-date-picker>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="邮箱地址">
                                    <el-input v-model="formData.email"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="会员备注">
                                    <el-input v-model="formData.remark" type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- 编辑标签弹层 -->
            <div class="add-form">
                <el-dialog title="编辑会员档案" :visible.sync="dialogFormVisible4Edit">
                    <!-- 被校验的表单必须有这个属性 ref -->
                    <el-form ref="dataEditForm" :model="formData" :rules="rules" label-position="right"
                             label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="用户姓名" prop="name">
                                    <el-input v-model="formData.name"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="性别">
                                    <el-select v-model="formData.sex">
                                        <el-option label="男" value="1"></el-option>
                                        <el-option label="女" value="2"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="身份证号" prop="idcard">
                                    <el-input v-model="formData.idcard"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="手机号码" prop="phonenumber">
                                    <el-input v-model="formData.phonenumber"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="出生日期">
                                    <!--       在el-for中添加时间模块       -->
                                    <el-date-picker type="date" placeholder="选择日期" v-model="formData.birthday"
                                                    style="width: 100%;"></el-date-picker>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="注册时间">
                                    <!--       在el-for中添加时间模块       -->
                                    <el-date-picker type="date" placeholder="选择日期" v-model="formData.regtime"
                                                    style="width: 100%;"></el-date-picker>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="邮箱地址">
                                    <el-input v-model="formData.email"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="会员备注">
                                    <el-input v-model="formData.remark" type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            //搜索条件列表
            sexList:['不限','男','女'],
            regList:['不限',2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021],
            ageList:['不限','0-18','19-29','30-39','40-49','50-59','60以上'],
            pagination: { //分页相关模型数据
                currentPage: 1, //当前页码
                pageSize: 10, //每页显示的记录数
                total: 0, //总记录数
                queryString: null, //查询条件
                sex:'不限',
                age:'不限',
                reg:'不限'
            },
            dataList: [], //当前页要展示的分页列表数据
            formData: {}, //表单数据
            dialogFormVisible: false, //增加表单是否可见
            dialogFormVisible4Edit: false, //编辑表单是否可见
            rules: { //校验规则
                phonenumber: [{
                    required: true,
                    message: '项目编码为必填项',
                    trigger: 'blur'
                }],
                name: [{
                    required: true,
                    message: '项目名称为必填项',
                    trigger: 'blur'
                }]
            }
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();
        },
        methods: {
            setSex(sex){this.pagination.sex=sex;console.log(this.pagination.sex);this.findPage();},
            setReg(reg){this.pagination.reg=reg;console.log(this.pagination.reg);this.findPage();},
            setAge(age){this.pagination.age=age;console.log(this.pagination.age);this.findPage();},
            //分页查询
            findPage() {
                axios.post("http://localhost:9003/member/queryAllMember", this.pagination).then(response => {
                    this.dataList = response.data.rows;
                    this.pagination.total = response.data.total;
                });
            },
            //点击确定按钮编辑
            handleEdit() {
                this.$refs['dataEditForm'].validate(valid => {
                    if (valid) {
                        axios.post("http://localhost:9003/member/updateMember", this.formData).then(response => {
                            if (response.data.flag) {
                                this.$message({
                                    message: response.data.message,
                                    type: 'success'
                                });
                                this.findPage();
                                this.dialogFormVisible4Edit = false;
                            } else {
                                this.$message().error("数据校验失败,请检查数据")
                            }
                        })
                    }
                })
            },

            //添加检查项
            handleAdd() {
                this.$refs['dataAddForm'].validate((valid) => {
                    if (valid) {
                        axios.post("http://localhost:9003/member/addMember", this.formData).then(response => {
                            if (response.data.flag) {
                                this.$message({
                                    message: response.data.message,
                                    type: 'success'
                                });
                                this.findPage(); //调用分页方法
                                this.dialogFormVisible = false; //关闭添加框
                            } else {
                                this.$message().error(response.data.message);
                            }
                        });
                    } else {
                        this.message().error("数据校验失败,请检查数据");
                    }
                })
            },
            //重置表单
            resetForm() {
                this.formData = {}
            },
            //弹出添加窗口
            handleCreate() {
                this.resetForm();
                this.dialogFormVisible = true;
            },
            //弹出编辑窗口
            handleUpdate(row) {
               this.dialogFormVisible4Edit=true;
               this.formData=row;
            },
            //切换页码显示分页信息
            handleCurrentChange(currentPage) {
                //将点击的页码给我们的当前页从新赋值
                this.pagination.currentPage = currentPage;
                //调用分页查询方法
                this.findPage();
            },
            // 删除检查项
            handleDelete(row) {
                this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.get("http://localhost:9003/member/deleteMember?id="+row.id).then(response => {
                        if (response.data.flag) {
                            this.$message({
                                type: 'success',
                                message: response.data.message
                            });
                            this.findPage();
                        } else {
                            this.$message({
                                type: 'error',
                                message: '该检查项已经添加到检查组中无法删除,请先删除检查组'
                            })
                        }
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            }
        }
    })
</script>

</html>